package com.hangwei.paperless.view.window;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;

import com.hangwei.paperless.MainSeeActivity;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.AcceptCheckInfo;
import com.hangwei.paperless.model.bean.DictBean;
import com.hangwei.paperless.presenter.StaticPresenter;
import com.hangwei.paperless.view.BaseView;
import com.hangwei.paperless.view.SealHelper;
import com.hangwei.paperless.view.window.acceptsee.AcceptItem0See;
import com.hangwei.paperless.view.window.acceptsee.AcceptItem1See;
import com.hangwei.paperless.view.window.acceptsee.AcceptItem2See;
import com.hangwei.paperless.view.window.acceptsee.AcceptItem3See;
import com.hangwei.paperless.view.window.acceptsee.AcceptItem4See;
import com.hangwei.paperless.view.window.acceptsee.AcceptItem5See;
import com.twelve.all.net.CallBack;
import com.twelve.all.utils.LoadingDialog;
import com.twelve.all.utils.SPKey;
import com.twelve.all.utils.SPUtil;

import java.util.List;

/**
 * Created by 张龙臣 on 2020/11/24.
 */

public class AcceptCheckSee extends BaseView<MainSeeActivity, AcceptCheckInfo> {

    private AcceptItem0See mItem0;
    private AcceptItem1See mItem1;
    private AcceptItem2See mItem2;
    private AcceptItem3See mItem3;
    private AcceptItem4See mItem4;
    private AcceptItem5See mItem5;
    private EditText mEtRemark;
    public static List<DictBean> mAcceptStatus;
    private FrameLayout mFlUserSeal;
    private FrameLayout mFlInspector;

    public AcceptCheckSee(MainSeeActivity activity) {
        super(activity);
    }

    @Override
    protected View initView() {
        View inflate = LayoutInflater.from(mActivity).inflate(R.layout.page_see_accept_check, null);
        FrameLayout fl5 = (FrameLayout) inflate.findViewById(R.id.fl5);
        FrameLayout fl4 = (FrameLayout) inflate.findViewById(R.id.fl4);
        FrameLayout fl3 = (FrameLayout) inflate.findViewById(R.id.fl3);
        FrameLayout fl2 = (FrameLayout) inflate.findViewById(R.id.fl2);
        FrameLayout fl1 = (FrameLayout) inflate.findViewById(R.id.fl1);
        FrameLayout fl0 = (FrameLayout) inflate.findViewById(R.id.fl0);


        mEtRemark = inflate.findViewById(R.id.etRemark);
        mFlUserSeal = inflate.findViewById(R.id.flUserSeal);
        mFlInspector = inflate.findViewById(R.id.flInspector);

        mItem0 = new AcceptItem0See(mActivity);
        fl0.addView(mItem0.getItemView());
        mItem1 = new AcceptItem1See(mActivity);
        fl1.addView(mItem1.getItemView());
        mItem2 = new AcceptItem2See(mActivity);
        fl2.addView(mItem2.getItemView());
        mItem3 = new AcceptItem3See(mActivity);
        fl3.addView(mItem3.getItemView());
        mItem4 = new AcceptItem4See(mActivity);
        fl4.addView(mItem4.getItemView());
        mItem5 = new AcceptItem5See(mActivity);
        fl5.addView(mItem5.getItemView());
        initData();

        return inflate;
    }

    @Override
    public void bindData(AcceptCheckInfo acceptCheckBean) {
        SealHelper sealHelper = new SealHelper(mActivity) {
            @Override
            protected void onSeal() {
            }
        };
        sealHelper.bindData(new SealHelper.SealBean(true,acceptCheckBean.technicianStampId, acceptCheckBean.technicianId, acceptCheckBean.technicianStampTypeCode, acceptCheckBean.technicianStampCode, acceptCheckBean.technicianDate, acceptCheckBean.technician,true));
        mFlUserSeal.addView(sealHelper.getItemView());
        SealHelper sealHelper1 = new SealHelper(mActivity) {
            @Override
            protected void onSeal() {
            }
        };
        sealHelper1.bindData(new SealHelper.SealBean(true,acceptCheckBean.technicianStampId, acceptCheckBean.inspectorId, acceptCheckBean.inspectorStampTypeCode, acceptCheckBean.inspectorStampCode, acceptCheckBean.inspectorDate, acceptCheckBean.inspector, !TextUtils.isEmpty(acceptCheckBean.technicianId)));
        mFlInspector.addView(sealHelper1.getItemView());
        mItem0.bindData(acceptCheckBean.T1);
        mItem1.bindData(acceptCheckBean.T2);
        mItem2.bindData(acceptCheckBean.T3);
        mItem3.bindData(acceptCheckBean.T4);
        mItem4.bindData(acceptCheckBean.T5);
        mItem5.bindData(acceptCheckBean.T6);
        mEtRemark.setText(acceptCheckBean.remark);

    }

    private void initData() {
        final LoadingDialog dialog = new LoadingDialog(mActivity);
        dialog.show();
        String userId = SPUtil.getString(SPKey.Account.USER_ID);
        StaticPresenter.getReceiveRecordSheet(userId, mActivity.getBillId(), new CallBack<AcceptCheckInfo>() {
            @Override
            public void onCompleted(AcceptCheckInfo acceptCheckBean) {
                dialog.dismiss();
                bindData(acceptCheckBean);
            }

            @Override
            public void onError() {
                dialog.dismiss();
            }
        });
        StaticPresenter.getDictByIdOrCode(userId, null, "ReceivingCondition", 1, 30, new CallBack<List<DictBean>>() {
            @Override
            public void onCompleted(List<DictBean> dictBeans) {
                mAcceptStatus = dictBeans;
            }

            @Override
            public void onError() {

            }
        });
    }
}
